<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% dashboard ||= false %>
<% unless dashboard %>
  <tr class="course-list-table-row">
<% end %>
<% if current_enrollment.workflow_state == "invited" && !current_enrollment.inactive? %>
  <div class="<%= dashboard ? 'communication_message dashboard_notification alert alert-info' : 'reminder' %>">
    <h2><a href="<%= course_path(current_enrollment.course_id, :invitation => current_enrollment.uuid) %>"><%= current_enrollment.long_name %></a></h2>
    <div class="body">
      {{> views/shared/invitation}}
    </div>
  </div>
<% else %>
  <% show_link = [:active, :invited, :accepted, :completed].include?(current_enrollment.state_based_on_date) && (!current_enrollment.course.unpublished? || current_enrollment.admin?) %>
      <% if @show_star_column %>
      <td class="course-list-star-column">
      <% favorite_course = @favorite_course_ids.include?(current_enrollment.course_id) %>
      <% past_course = @past_enrollments.include? current_enrollment %>
      <% favorite_past_course = past_course && favorite_course %>
      <% tooltip_message = t('nonfavorited_tooltip', "Click to add to the courses menu.") if !favorite_course %>
      <% tooltip_message = t("This course cannot be added to the courses menu at this time.") if (!show_link || past_course) %>
      <% tooltip_message = t('favorited_tooltip', "Click to remove from the courses menu.") if favorite_course || favorite_past_course %>
        <span
          class="<%= "course-list-favorite-course" if favorite_course %> <%= "course-list-not-favoritable disabled" if (!show_link || favorite_past_course) %> <%= "course-list-favoritable" if show_link %>"
          data-tooltip="bottom"
          title="<%= tooltip_message %>"
          role="button"
          tabindex="0"
          data-course-id="<%= current_enrollment.course_id %>"
          <% if (show_link && (favorite_past_course || !(past_course && !favorite_course))) %>
              <%= "data-favorite-url=#{api_v1_add_favorite_course_url(current_enrollment.course_id)}" %>
          <% end %>
        >
          <i class="<%= "course-list-favorite-icon #{favorite_course ? "icon-star" : "icon-star-light"}" %>"></i>
          <span id="course_list_screenreader_message_<%= current_enrollment.course_id %>" class="screenreader-only">
            <%= tooltip_message %>
          </span>
        </span>
      </td>
      <% end %>

      <% course_color = @current_user.custom_colors["course_#{current_enrollment.course_id}"] %>
      <td class="course-list-course-title-column
        <%= "course-list-no-left-border" if @show_star_column %>
        <%= "course-list-not-favoritable" unless @show_star_column %>">
        <% if course_color.present? %>
          <span aria-hidden="true" class="course-color-block" style="<%= "color: #{course_color};" %>" ></span>
        <% end %>
        <% if show_link %><a href="<%= course_path(current_enrollment.course_id) %>" title="<%= current_enrollment.course.name %>"><% end %>
        <span class="name">
          <%= current_enrollment.course.name %>
        </span>
        <% if show_link %></a>
        <% end %>
      </td>

      <td class="course-list-no-left-border course-list-nickname-column">
        <%= current_enrollment.course.nickname_for(@current_user, nil) %>
      </td>

      <td class="course-list-no-left-border course-list-term-column">
      <% if current_enrollment.course.enrollment_term.default_term? %>
        <span class="screenreader-only"><%= current_enrollment.course.enrollment_term.name %></span>
      <% else %>
        <%= current_enrollment.course.enrollment_term.name %>
      <% end %>
      </td>

      <td class="course-list-no-left-border course-list-enrolled-as-column">
        <%= current_enrollment.readable_role_name %>
      </td>

      <td class="course-list-no-left-border course-list-published-column ">
        <% if current_enrollment.course.created? || current_enrollment.course.claimed? %>
            <span data-tooltip title="{{#t}}This course has not been published. Students should contact the course instructor for access.") %>"><%= t('unpublished_course', "No{{/t}}</span>
             <span class="screenreader-only">{{#t}}This course has not been published. Students should contact the course instructor for access.{{/t}}</span>
        <% else %>
            <span data-tooltip title="{{#t}}This course has been published.") %>"><%= t('published_course', "Yes{{/t}}</span>
             <span class="screenreader-only">{{#t}}This course has been published.{{/t}}</span>
        <% end %>
      </td>

<% end %>
<% unless dashboard %>
  </tr>
<% end %>
